//
//  UIButton + Extension.swift
//  Residual_memmem
//
//  Created by 武振磊 on 16/7/21.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

extension UIButton{
    ///   便利构造函数
    ///   - parameter imageName:     imageName
    ///   - parameter backImageName: backImageName
    ///   - returns: UIButton
    convenience init(imageName: String, backImageName: String){
        self.init()
     
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: UIControlState.Highlighted)
        
        sizeToFit()
    }
    
    ///   遍历构造函数
    ///   - parameter title:     title
    ///   - parameter color:     titleColor
    ///   - parameter font:      titleFont
    ///   - parameter imageName: imageName
    ///   - returns: UIButton
    convenience init(title: String, color: UIColor, font: CGFloat,imageName: String){
        
        self.init()
        setTitle(title, forState: UIControlState.Normal)
        setTitleColor(color, forState: UIControlState.Normal)
        titleLabel?.font = UIFont.systemFontOfSize(font)
        
        setBackgroundImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
    }

}
